package com.oceansoft.core.common.util;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * IO相关
 * 
 * @author Administrator
 * 
 */
public final class IOUtil {
	public static Map<String, File> listAllFileNames(File base) {

		return listAllFileNames(base, "");
	}

	private static Map<String, File> listAllFileNames(File base, String prefix) {
		if ((!(base.canRead())) || (!(base.isDirectory()))) {
			throw new IllegalArgumentException(base.getAbsolutePath());
		}
		Map<String, File> map = new LinkedHashMap<String, File>();
		File[] hits = base.listFiles();
		for (int i = 0; i < hits.length; ++i) {
			File hit = hits[i];
			if (hit.canRead()) {
				if (hit.isDirectory()) {
					map.putAll(listAllFileNames(hit, prefix + "/" + hit.getName()));
				} else {
					map.put(prefix + "/" + hit.getName(), hit);
				}
			}
		}
		map.put(prefix, base);
		return map;
	}
}
